<template>
    <div id="appointment">
        <div class="container">
            <div class="handle-box">
                <el-form ref="form" :inline="true" :model="form">
                    <el-form-item>
                        <el-button type="primary" @click="handleSearch(90)">90日下线歌曲</el-button>
                    </el-form-item>

                    <el-form-item>
                        <el-button type="default" @click="handleSearch(60)">60日下线歌曲</el-button>
                    </el-form-item>

                    <el-form-item>
                        <el-button type="default" @click="handleSearch(30)">30日下线歌曲</el-button>
                    </el-form-item>

                    <el-form-item>
                        <el-button type="default" @click="handleSearch(7)">7日下线歌曲</el-button>
                    </el-form-item>

                    <el-form-item>
                        <el-button type="default" @click="handleSearch(3)">3日下线歌曲</el-button>
                    </el-form-item>
                </el-form>
            </div>
            <el-table
                :data="tableData"
                border
                class="table"
                ref="multipleTable"
                header-cell-class-name="table-header"
                @selection-change="handleSelectionChange"
            >
                <el-table-column width="auto" label="合同截止日期" align="center">
                    <template slot-scope="scope">{{ scope.row.contractEnd }}</template>
                </el-table-column>

                <el-table-column width="auto" label="CPID" align="center">
                    <template slot-scope="scope">{{ scope.row.id }}</template>
                </el-table-column>

                <el-table-column width="auto" label="cp名称" align="center">
                    <template slot-scope="scope">{{ scope.row.name }}</template>
                </el-table-column>

                <el-table-column width="auto" label="状态" align="center">
                    <template slot-scope="scope">{{
                        scope.row.status == 0
                            ? '保存状态'
                            : scope.row.status == 1
                            ? '待初审'
                            : scope.row.status == -1
                            ? '退回修改'
                            : scope.row.status == 2
                            ? '初审通过'
                            : scope.row.status == -2
                            ? '初审不通过'
                            : scope.row.status == 3
                            ? '评审通过'
                            : scope.row.status == -3
                            ? '评审不通过'
                            : scope.row.status == 4
                            ? '合同签署中'
                            : scope.row.status == 5
                            ? '重提待审'
                            : scope.row.status == 9
                            ? '业务开通'
                            : scope.row.status == -9
                            ? '变更注销(变更主体后原接入记录状态'
                            : ''
                    }}</template>
                </el-table-column>

                <el-table-column width="auto" label="创建时间" align="center">
                    <template slot-scope="scope">{{ scope.row.createTime }}</template>
                </el-table-column>

                <el-table-column width="auto" label="歌曲详情" align="center">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="handleSee(scope.$index, scope.row)">
                            <!-- 查看 -->
                            {{ $t('m.seeBtn') }}
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>

            <div class="pagination">
                <el-pagination
                    background
                    layout="total,sizes, prev, pager, next, jumper"
                    :page-sizes="[5, 10, 20, 30]"
                    @size-change="handleSizeChange"
                    :current-page="query.pageIndex"
                    :page-size="query.pageSize"
                    :total="pageTotal"
                    @current-change="handlePageChange"
                ></el-pagination>
            </div>
        </div>
    </div>
</template>

<script>
  import { debounce, throttle } from '@/utils/utils.js';
  export default {
      name: 'Appointment',
      data() {
          return {
              query: {
                  pageIndex: 1,
                  pageSize: 10,
                  day: 10
              },
              tableData: [],
              pageTotal: 0,
              form: {}
          };
      },
      activated() {
          this.getData();
      },
      methods: {
          handleSee(index, row) {
              this.$router.replace({
                  path: '/song_1/detail',
                  query: {
                      id: row.id
                  }
              });
          },
          async getData() {
              try {
                  let url = '/cpp/renewalContract';
                  let { data: res } = await this.$http[1].get(url, {
                      params: this.$removeField({
                          day: this.query.day,
                          page: this.query.pageIndex,
                          size: this.query.pageSize
                      })
                  });
                  if (res.code != '0000') {
                      throw new Error(res.message);
                  }
                  console.log('急需续约', res);
                  if (res.data.content && res.data.content.length != 0) {
                      res.data.content.map((item) => {
                          item.contractEnd = this.$dateFormat(item.contractEnd, '', '-');
                          item.createTime = this.$dateFormat(item.createTime, '', '-');
                      });
                      this.tableData = res.data.content;
                      this.pageTotal = res.data.totalElements;
                  } else {
                      this.tableData = [];
                      this.pageTotal = 0;
                  }
              } catch (err) {
                  console.dir(err);
                  this.$message.error({
                      message: err.message,
                      duration: 1500
                  });
              }
          },
          // 触发搜索按钮
          // handleSearch(day) {
          //     this.$set(this.query, 'pageIndex', 1);
          //     this.$set(this.query, 'day', day);
          //     this.getData();
          // },

          handleSearch: debounce(function (day) {
              this.$set(this.query, 'pageIndex', 1);
              this.$set(this.query, 'day', day);
              this.getData();
          }, 300),

          // 多选操作
          handleSelectionChange(val) {
              // this.multipleSelection = val;
          },

          // 分页导航
          handlePageChange(val) {
              this.$set(this.query, 'pageIndex', val);
              this.getData();
          },
          handleSizeChange(val) {
              this.$set(this.query, 'pageSize', val);
              this.getData();
          }
      }
  };
</script>

<style lang="scss">
  #appointment {
      .table-header {
          .cell {
              white-space: nowrap !important;
          }
      }
      .handle-box {
          margin-bottom: 20px;
      }

      .handle-select {
          width: 120px;
      }

      .handle-input {
          /* width: 300px; */
          width: 69px;
          height: 28px;
          display: inline-block;
      }
      .table {
          width: 100%;
          font-size: 14px;
      }
      /* .red {
      color: #ff0000;
  } */
      .mr10 {
          margin-right: 10px;
      }
      .table-td-thumb {
          display: block;
          margin: auto;
          width: 40px;
          height: 40px;
      }
  }
</style>
